package com.feng.freader.view.sudo.bus;

import static com.feng.freader.view.sudo.view.NineGridView.NUM;
import static com.feng.freader.view.sudo.view.NineGridView.SIZE;
import static com.feng.freader.view.sudo.view.NineGridView.ZERO;

import java.util.Arrays;
import java.util.Random;

import android.util.Log;
//import static secondriver.sudo.view.NineGridView.ZERO;
//import static secondriver.sudo.view.NineGridView.SIZE;
//import static secondriver.sudo.view.NineGridView.NUM;

public class GameData {

	private static final String TAG = "GameData";
	private static Random random = new Random();

	private static final String[] DATA_GRID = new String[] {
			"587926431_914357628_632814597_326781945_478593162_195462873_869275314_253149786_741638259",
			"657928431_491573628_832164597_974612385_563847912_128395746_319256874_246789153_785431269",
			"987625431_315497628_246138597_539281746_671349852_428576319_753962184_894713265_162854973" };

	static int[] getGameOriginalStatus() {
		int index = random.nextInt(DATA_GRID.length);
		String value = DATA_GRID[index].replace("_", "");
		Log.i(TAG, "grid=" + value);
		int[] v = new int[value.length()];
		for (int i = 0, l = value.length(); i < l; i++) {
			v[i] = value.charAt(i) - '0';
		}
		return v;
	}

	static int[] getGameInitialStatus(GameLevel level, int[] original) {
		int[] v = Arrays.copyOf(original, original.length);
		for (int i = 0; i < SIZE; i += NUM) {
			for (int j = 0; j < SIZE; j += NUM) {
				int temp = -1;
				int size = level.getV();
				while (size > 0) {
					int x = random.nextInt(NUM) + i;
					int y = random.nextInt(NUM) + j;
					int index = x + SIZE * y;
					if (temp != index && v[index] != ZERO) {
						v[index] = ZERO;
						temp = index;
						size--;
					}
				}
			}
		}
		return v;
	}

}
